* switch to channel and update
  * sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
    \ don't use nixos-unstable-small because xfce4 has no icons (eg. for xfce4-terminal)
  * time sudo nixos-rebuild switch --upgrade
* just switch
  \ CAVEAT: new kernel modules(such as vboxsf.ko) cannot be found via modprobe until you reboot into that newly built profile, else you can find them in /nix/store/ somewhere and can insmod (not modprobe!) vboxguest first then vboxsf.
  * time sudo nixos-rebuild switch

* free space
  \ src: https://nixos.org/releases/nixos/unstable/nixos-16.09pre79453.32b7b00/manual/index.html#sec-nix-gc
  * hard-linking / optimise
    * time sudo -i -- nix-store --optimise
  * time sudo -i -- nix-collect-garbage
    \ won't delete old configs (like from grub menu)
    * to also delete old configs(like from grub menu, unsure if grub menu is updated tho)
      \ time sudo -i -- nix-collect-garbage -d

* use git repo as channel
  \ this is a 'sudo git clone https://github.com/NixOS/nixpkgs.git' then 'sudo git remote add channels https://github.com/nixos/nixpkgs-channels' then 'sudo git fetch --all'(always do this fetch before the reset that follows to keep those refs up to date!) then 'git reset --hard channels/nixos-unstable' (or 'channels/nixos-16.03' for the current stable which seems ahead of nixos-unstable ) if I want to use the binaries and compile less, or use latest git and compile more via 'sudo git reset --hard origin/master' and then 'time sudo nixos-rebuild switch --fallback' (--fallback to compile from sources, they say) - so, now the question is: do I need to add --update near --fallback or not?! apparently not, but also this is the equivalent cmd: https://github.com/NixOS/nix/issues/807#issuecomment-209895935
  \ in /etc/nixos/configuration.nix add:
  \ nixPath = [ "nixpkgs=/etc/nixos/nixpkgs" ];
  \ under: nix = { };
  \

* nix-repl
  \ thanks to 'clever' on #nixos freenode irc
  * tabcompletion
    * :l <nixpkgs>
      \ Added 6145 variables.
    * type: firefox  then tab tab
      \ to see completions
  * build package hello with debugging info so you can run gdb
    * :b enableDebugging hello
* find which package has command
  * hack
    \ thanks to 'clever' on #nixos freenode irc
    \ src: http://pastebin.com/raw/tnKSSshd
    * # sqlite3 /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite 
    * select * from Programs where name = "lspci";

* packages
  \ src: https://bluishcoder.co.nz/2014/05/14/installing-nixos-with-encrypted-root-on-thinkpad-w540.html
  * search for package name
    \ nix-env -qaP '*'|grep -i -- vim
  * locally add your own packages(for your current user, not globally)
    \ nix-env -i vim
  * locally remove packages
    \ nix-env -e vim

* sane configuration.nix example
  \ https://github.com/manpages/dotfiles/blob/ac402986172c9a4842d067316979cc23a2a187ea/nixos/gpu.nix
  \ switch to master to see latest version, I guess.


* how to connect from host to the ssh from virtualbox
  - ssh root@192.168.0.1  if used Bridged
  * ssh ... if using NAT
    * you need to forward port 22
      \ http://ask.xmodulo.com/access-nat-guest-from-host-virtualbox.html
      * ifconfig
        \ see what's the ip of the guest OS
        \ 10.0.2.15
      * Machine->Settings->Network->Port Forwarding (button)
        \ Name: sshd
        \ Protocol: TCP
        \ Host IP: 127.0.0.111
        \ Host Port: 8822
        \ ^ (any unused port higher than 1024) unless u're running virtualbox as root(don't!)
        \ Guest IP: 10.0.2.15
        \ Guest Port: 22
    * ssh -v -p 8822 127.0.0.111 -l root

* to mount vboxsf shares while booted from the iso
  * vim /etc/nixos/configuration.nix
    \ virtualisation.virtualbox.guest.enable = true;
    \ wq! (because it's readonly!)
  * time nixos-rebuild switch
    \ takes like 10min
  * now you must find 2 modules
    \ eg. find /nix/store/ -iname vboxsf\*
    \ should be: /nix/store/hashhere-kernel-modules-shrunk/lib/modules/4.4.8/misc/vboxsf.ko
    * insmod $thatdir/vboxguest.ko
    * insmod $thatdir/vboxsf.ko
  * now you can mount
    \ mount -t vboxsf vmsharedfolder /vmsh

* fails:
  * malformed database
    \ error (ignored): finalizing statement: database disk image is malformed
    \ error: error getting valid paths: database disk image is malformed
    \
    \ solution src: http://lists.science.uu.nl/pipermail/nix-dev/2015-June/017410.html
    * backup /nix/var/nix/db/db.sqlite
    * sqlite3 /nix/var/nix/db/db.sqlite 'pragma integrity_check'
      \ well... sqlite3: command not found
      \ and can't add any new packages because database malformed...

* how to fix broken nixos-rebuild
  \ https://beyermatthias.de/blog/2015/11/27/nixos-on-unstable-how-to-fix-a-broken-nixos-rebuild/

